var express = require('express');
var router = express.Router();
var BaseData = require('../.././config/db');
db = new BaseData();
db.connection.connect();

/* GET home page. */

router.get('/', function(req, res, next) {
	if(req.session.token) {
		var Str = req.session.token;
		var User_id = db.Toolaes(Str.toString().split("_")[0], "Decrypt");
		res.render('admin/link/', {
			User_id: User_id,
			title: "站点设置",
			Parameter: 3
		});
	} else {
		res.render('admin/link/', {
			User_id: null,
			title: "站点设置",
			Parameter: 3,
			Config: db.GetConfig(db.linkConfig)
		});
	}
})

router.post('/', function(req, res, next) {
	console.log(JSON.stringify(req.body))
	if(db.SetConfig(db.SiteConfig, JSON.stringify(req.body))) {
		res.json({
			code: 3002,
			msg: '保存失败'
		})
		return false;
	}
	res.json({
		code: 3000,
		msg: '保存成功'
	})
})

module.exports = router;